package org.openjava.utils;


import java.util.regex.Matcher;
import java.util.regex.Pattern;



public class StringUtils {
	public static String capitalize(String origin){
		return Character.toTitleCase(origin.charAt(0)) + origin.substring(1);
	}
	
	public static String unCapitalize(String origin){
		return Character.toLowerCase(origin.charAt(0)) + origin.substring(1);
	}
	public static boolean isEmpty(String string){
		return string == null || string.length() == 0;
	}
	
	public static boolean isNotEmpty(String str){
		return !isEmpty(str);
	}
	
	public static String join(String[] strArray,String delim){
		String delimiter = ",";
		if(delim != null){
			delimiter = delim;
		}
		StringBuffer buffer = new StringBuffer("[");
		for(int i=0,j = strArray.length;i < j;i ++){
			buffer.append(strArray[i]).append(delimiter);
		}
		buffer.deleteCharAt(buffer.length() - 1).append("]");
		return buffer.toString();
	}
	 
	
	public static int countSubCount(String origin,String sub){
		Pattern pattern  = Pattern.compile("([\\[\\]\\^\\$]{1})");
		System.out.println(pattern);
		Matcher matcher = pattern.matcher(sub);
		StringBuffer buffer = new StringBuffer();
		while(matcher.find()){
			matcher.appendReplacement(buffer,"\\\\" + matcher.group(1));
		}
		matcher.appendTail(buffer);
		System.out.println(buffer);
		
		pattern = Pattern.compile(buffer.toString());
		matcher = pattern.matcher(origin);
		return matcher.groupCount();
	}
 
}
